<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        const url = 'http://www.liulongbin.top:3006/api/news'; // url + '?name=zhangsan&age=18'

        // 对象转query string   实战9题
        const params = {
            name: 'zs', // 'name=zs'
            age: 18,    // 'age=18'
        };

        // 1. 创建实例
        const xhr = new XMLHttpRequest();
        // 2. 填写接口信息
        xhr.open('get', `${url}?${Object.keys(params).map(k => `${k}=${params[k]}`).join('&')}`);
        // 3. 发送
        xhr.send();
        // 4. 接返回值
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                console.log(JSON.parse(xhr.responseText));
            }
        };

    </script>
</body>
</html>